<?php
// 注册 API 错误处理函数，统一指向 App\Exception\Handle。
app('api.exception')->register(function (Exception $exception) {
    $request = \Illuminate\Http\Request::capture();
    return app('App\Exceptions\Handler')->render($request, $exception);
});

$api = app('api.router');

$group = [
    'version' => 'v1', // 这里一定要写，不然服务器 composer install 命令会报错！
    'namespace' => 'App\Http\Controllers',
];

// 不需要验证 access_token 的路由组。
$api->group($group, function ($api) {
    $api->post('auth/login', 'AuthController@login');
    $api->post('auth/send_code', 'AuthController@sendAuthCode');
    $api->post('auth/check_code', 'AuthController@checkAuthCode');
    $api->post('auth/check_version', 'AuthController@checkVersion');
    $api->post('auth/refresh', 'AuthController@refresh');
    $api->post('auth/reset_password', 'AuthController@resetPassword');
    $api->post('auth/wechat_authorize', 'AuthController@wechatAuthorize');
    $api->post('auth/change_phone_binding', 'AuthController@changePhoneBinding');
    $api->post('auth/solve_phone_binding_conflict', 'AuthController@solvePhoneBindingConflict');
    $api->post('auth/reset_password', 'AuthController@resetPassword');
    $api->post('auth/youzan_init_token', 'AuthController@youzanInitToken');
    $api->post('user/register', 'UserController@register');
    $api->get('youzan/items_onsale', 'YouzanController@getItemsOnsale');
    $api->get('youzan/carousels', 'YouzanController@getCarousels');
});

// 需要验证 access_token 的路由组。
$group['middleware'][] = 'check_token';
$api->group($group, function ($api) {
    $api->get('auth/me', 'UserController@getLoginUserProfile');
    $api->post('auth/me', 'UserController@updateUserProfile');
    $api->post('auth/youzan_login', 'AuthController@youzanLogin'); // 有赞商城登录。
    $api->post('auth/change_wechat_binding', 'AuthController@changeWechatBinding');
    $api->post('auth/solve_wechat_binding_conflict', 'AuthController@solveWechatBindingConflict');
    $api->get('auth/get_oss_post_options', 'AuthController@getOssPostOptions');
    $api->post('user/change_avatar', 'UserController@changeAvatar');
    $api->post('feedback', 'FeedbackController@store');
    $api->post('feature/check_text', 'FeatureController@checkText');
    $api->post('version', 'FeatureController@changeVersion');
});